package com.jsh.erp.controller;

import com.jsh.erp.service.depotHead.DepotHeadService;
import com.jsh.erp.utils.ErpInfo;
import com.jsh.erp.vo.SaleSumPriceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;

@RestController
@RequestMapping(value = "/sale-statistics")
@Api(tags = {"销售统计数据"})
public class SaleStatisticsController {

    @Resource
    DepotHeadService depotHeadService;

    @GetMapping(value = "/total-price")
    @ApiOperation(value = "总销售额")
    public String debtList(@RequestParam(value = "yearMonth", required = false) String yearMonth,
                           @RequestParam(value = "creator", required = false) Long creator) throws Exception {
        List<SaleSumPriceVo> list = depotHeadService.selectSaleSumPriceVoList(creator, yearMonth);
        Map<String, Object> map = new HashMap<>();
        map.put("rows", list);
        map.put("total", list.size());
        return returnJson(map, ErpInfo.OK.name, ErpInfo.OK.code);
    }
}
